from flask import Blueprint
from flask import g
from flask import redirect
from flask import request
from flask import url_for

from info.utils.common import user_login_data

admin_blu = Blueprint("admin", __name__)
from . import views


@admin_blu.before_request
@user_login_data
def check_admin():
    is_admin = False
    user = g.user
    if user:
        is_admin = user.is_admin
    if not is_admin and not request.url.endswith(url_for("admin.login")):
        return redirect("/")